#!/usr/bin/env python
# coding=utf-8

__metaclass__ = type


class ProtectMe:
    def __init__(self):
        self.me = "qiwsir"
        self.__name = "kivi"

    def __python(self):
        print "I love Python."

    def code(self):
        print "Which language do you like?"
        self.__python()  # 调用内部私有方法

    @property  # 访问内部私有变量 @property装饰器就是负责把一个方法变成属性调用的：
    def name(self):
        return self.__name

    def __str__(self):  # java的toString()
        return 'Student object (name: %s)' % self.name

    __repr__ = __str__  # __repr__()返回程序开发者看到的字符串，也就是说，__repr__()是为调试服务的


class Student(object):
    @property  # 把一个getter方法变成属性
    def birth(self):
        return self._birth

    @birth.setter  # 负责把一个setter方法变成属性赋值
    def birth(self, value):
        self._birth = value

    @property
    def age(self):
        return 2014 - self._birth


if __name__ == "__main__":
    p = ProtectMe()
    print p
    print p.me
    p.code()
    print p.name
